package ynu.edu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import ynu.edu.mapper.IDeliveryAddressMapper;
import ynu.edu.po.DeliveryAddress;
import ynu.edu.service.IDeliveryAddressService;

import java.util.List;

@Service
public class DeliveryAddressServiceImpl implements IDeliveryAddressService {
    @Resource
    private IDeliveryAddressMapper deliveryAddressMapper;

    @Override
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) {
        QueryWrapper<DeliveryAddress> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId).orderByAsc("daId");
        return deliveryAddressMapper.selectList(queryWrapper);
    }

    @Override
    public DeliveryAddress getDeliveryAddressById(Integer daId) {
        return deliveryAddressMapper.selectById(daId);
    }

    @Override
    public boolean saveDeliveryAddress(DeliveryAddress deliveryAddress) {
        return deliveryAddressMapper.insert(deliveryAddress) > 0;
    }

    @Override
    public boolean updateDeliveryAddress(DeliveryAddress deliveryAddress) {
        return deliveryAddressMapper.updateById(deliveryAddress) > 0;
    }

    @Override
    public boolean removeDeliveryAddress(Integer daId) {
        return deliveryAddressMapper.deleteById(daId) > 0;
    }
}
